package com.taiyo.modules.sys.controller;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import com.baidu.ueditor.ActionEnter;

@Controller
@Transactional
@RequestMapping("/")
public class FileUploadController {
	@RequestMapping(value = "/ueditor")
	public void config(HttpServletRequest request, HttpServletResponse response) {
		response.setContentType("application/json");
		String rootPath = request.getSession().getServletContext().getRealPath("/");
		try {
			String exec = new ActionEnter(request, rootPath).exec();
			String action = request.getParameter("action");  
 
			if( action!=null &&   
			   (action.equals("listfile") || action.equals("listimage") ) ){  
			    rootPath = rootPath.replace("\\", "/");  
			    exec = exec.replaceAll(rootPath, "/");  
			}  

			PrintWriter writer = response.getWriter();

			writer.write(exec);
			writer.flush();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
